<template>
  <ul>
    <li @click.prevent="goTO(item)"  v-for="(item, index) in items" :key="index">
      <div class="content">
          <span class="num">
          {{index+1 }}、
        </span>
        <span class="font">
          {{ item["题名"] }}
        </span>
        <span class="i">
          {{ item.time }}
        </span>

        <div class="recommond" v-if="isshow">
          推荐者：<span>{{ 
           item["姓名"]==""? item["推荐人账号"]:item["姓名"]
             }}</span>
        </div>
        <div  class="recommond" v-else>
         被推荐者：<span>{{ 
           item["姓名"]==""? item["被推荐人账号"]:item["姓名"]
            }}</span>
        </div>
      </div>
    </li>
  </ul>
</template>
<script>
export default {
  name: "list",

  data(){
   return{
     isshow:false,
   }
 
  },
  mounted() {
     if(this.infoType=="RecommendationToMe"){
       this.isshow=true
     }
   
  },
  props: {
    items: [],
    infoType:{
      type:String,
    }
  },
  watch: {
    items: {
      handler(n, o) { 
        for(var k in n) {  
         n[k]["time"] = myReplace(n[k].推荐时间.split(" ")[0],"/","-");
        } 
        // 用正则表达式进行替换的方法
        function myReplace(sInput,sChar,sReplaceChar) {
            if(sInput==""||sInput==undefined) {
                return "";
            }
            var oReg =new RegExp(sChar,"g");
            return sInput.replace(oReg, sReplaceChar);
        }
      },
      immediate: true, //刷新加载 立马触发一次handler
      deep: true, // 可以深度检测到 person 对象的属性值的变化
    },
  },
  methods: {
    goTO(item) { 
      let type = 1;
      let url = "";
      let data = JSON.stringify({
        dbcode: item.资源库代码 + "_METADATA",
        sysid: item.资源ID,
        fileName:item.文件名,
        dbname:item.来源数据库,
        vsm:item.SYS_VSM,
      });
      let ary = [
        "期刊",
        "博士",
        "硕士",
        "国内会议",
        "国际会议",
        "报纸",
        "年鉴",
        "中国专利",
        "海外专利",
        "国家标准",
        "行业标准",
        "中国标准",
        "国外标准",
        "成果",
        "法律法规",
        "工具书",
      ];
      ary.forEach((i) => {
        switch (item.资源来源数据库) {
          case i:
            type = 2;
            url =
              window.localStorage.mirrorUrl+
              item.资源库代码 +
              "&filename=" +
              item.资源文件名;
            break;
        }
      });
      if(type === 2) {
        this.$router.push({
            path: "/cnkiDetail",
            query: {
              type,
              data,
              url,
              tableName:item.表名,
              name: item.题名,
            }
        })
      }else {
        this.$router.push({
            path: "/detail",
            query: {
              type,
              data,
              url,
              tableName:item.表名,
              name: item.题名,
            }
        })
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../assets/css/zyy_phone.css";
@import "../../assets/css/search.css";
.list-header {
  min-height: calc(100vh - 120px);
  background: #fff;
  overflow-x: hidden; 
  ul {
    width: 100%;
     min-height:  calc(100vh - 120px);
    li {
      width: 100%;
      padding: 0 10px;
      border-bottom: 1px solid #ddd;
      .img {
        display: inline-block;
        width: 32px;
        height: 32px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .content {
        display: inline-block;
        height: 100%;
        vertical-align: top;
        width: calc(100% - 20px);
        position: relative;
        margin-bottom: 20px;
        margin-top: 20px;
        .font {
          width: calc(100% - 120px);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 14px;
          display: inline-block;
          font-weight: 600;
          vertical-align: middle;
        } 
        .num {
          vertical-align: middle;
        }
        .i {
          position: absolute;
          right: 0;
          width: 100px;
          text-align: right;
          color: #989898;
          top:2px;
        }
      }
      .recommond {
        margin-top:20px;
      }
    }

    li:last-child {
      margin-bottom: 0;
    }
  }
}
</style>